package com.hydl.power.controller;


import com.github.pagehelper.PageInfo;
import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.Device;
import com.hydl.power.pojo.TemperatureData;
import com.hydl.power.pojo.TemperatureDevice;
import com.hydl.power.service.TemperatureDeviceService;
import com.hydl.power.utils.Resp;
import io.micrometer.core.instrument.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("temperatureDevice")
@Api(value = "TemperatureDevice", tags = "测温设备控制类")
public class TemperatureDeviceController {



    @Autowired
    private TemperatureDeviceService temperatureDeviceService;




    @ApiOperation("线缆测温")
    @PostMapping("/getTemperatureDataList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "powerRoomId", value = "配电房", required = false, dataType = "String"),
    })
    public Resp<TemperatureData> getTemperatureDataList(String powerRoomId){
        List<TemperatureData> temperatureDataList = temperatureDeviceService.getTemperatureDataList(powerRoomId);
        return Resp.success(temperatureDataList);
    }


    @ApiOperation("漏电流和温度折线图")
    @PostMapping("/getTemperatureDataLine")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备sn", dataType = "String",defaultValue = "515269656955525366706566_2"),
            @ApiImplicitParam(paramType = "query", name = "time", value = "时间", dataType = "String",defaultValue = "2021-01-07"),
    })
    public Resp getTemperatureDataLine(String deviceId,String time){
        List<TemperatureData> temperatureDataList = temperatureDeviceService.getTemperatureDataLine(deviceId,time);
        return Resp.success(temperatureDataList);
    }






    // @LogAnnotation(module = "测温设备控制类",description = "测温设备列表")
    @ApiOperation("测温设备列表")
    @PostMapping("/getTemperatureDeviceList")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "显示个数", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "areaId", value = "城市", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "powerRoomId", value = "配电房", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String"),
    })
    public Resp<PageInfo<TemperatureDevice>> getTemperatureDeviceList(Integer pageNum,Integer pageSize,String areaId,String projectId,String powerRoomId,String token){
        PageInfo<TemperatureDevice> temperatureDeviceList = temperatureDeviceService.getTemperatureDeviceList(pageNum, pageSize, areaId, projectId, powerRoomId, token);
        return Resp.success(temperatureDeviceList);
    }






   // @LogAnnotation(module = "测温设备控制类",description = "新增测温设备")
    @PostMapping("/addTemperatureDevice")
    @ApiOperation(value = "新增测温设备", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceName", value = "设备名字", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "areaId", value = "地区id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "areaName", value = "地区名", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "projectName", value = "项目名", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "powerRoomId", value = "配电房id", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "powerRoomName", value = "配电房名", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceAddress", value = "设备地址", required = false,defaultValue = "", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "serialNumber", value = "设备编码", required = false,defaultValue = "", dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "gatewaySn", value = "网关sn",required = false,defaultValue = "07938132",dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceMessageAddress", value = "设备通讯地址",required = false,defaultValue = "",dataType = "String"),
    })
    public Resp addTemperatureDevice(String deviceName,String areaId,String areaName,String projectId,String projectName,String powerRoomId,String powerRoomName,String deviceAddress,String serialNumber, String gatewaySn,String deviceMessageAddress) {
        int i=temperatureDeviceService.addTemperatureDevice(deviceName, areaId, areaName,projectId, projectName,powerRoomId,powerRoomName, deviceAddress, serialNumber, gatewaySn, deviceMessageAddress);
        return Resp.success();

    }

    @LogAnnotation(module = "测温设备控制类",description = "删除测温设备")
    @PostMapping("/deleteTemperatureDeviceById")
    @ApiOperation(value = "删除测温设备", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "设备id",  dataType = "Integer"),
    })
    public Resp deleteTemperatureDeviceById(Integer id) {
        temperatureDeviceService.deleteTemperatureDeviceById(id);
        return Resp.success();
    }


    // @LogAnnotation(module = "测温设备控制类",description = "根据设备id查询设备")
    @PostMapping("/getTemperatureDeviceById")
    @ApiOperation(value = "根据设备id查询设备", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "deviceId", value = "设备id",  dataType = "String"),
    })
    public Resp getTemperatureDeviceById(String  deviceId) {
        TemperatureDevice temperatureDeviceByTemperatureDeviceId = temperatureDeviceService.getTemperatureDeviceByTemperatureDeviceId(deviceId);
        return Resp.success(temperatureDeviceByTemperatureDeviceId);
    }

    @LogAnnotation(module = "测温设备控制类",description = "修改测温设备")
    @PostMapping("/updateTemperatureDeviceById")
    @ApiOperation(value = "修改测温设备", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "设备id",  dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "deviceName", value = "设备名字", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceAddress", value = "设备地址", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "deviceMessageAddress", value = "设备通讯地址", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "serialNumber", value = "谁被编码", required = false, dataType = "String"),
    })
    public Resp updateTemperatureDeviceById(Integer id,String deviceName,String deviceAddress,String deviceMessageAddress,String serialNumber) {
        temperatureDeviceService.updateTemperatureDeviceById(id, deviceName, deviceAddress, deviceMessageAddress,serialNumber);
        return Resp.success();
    }

    // @LogAnnotation(module = "测温设备控制类",description = "根据设备id查询设备")
    @PostMapping("/queryDevice")
    @ApiOperation(value = "根据设备id查询设备", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "设备id",  dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "powerRoomId", value = "设备id",  dataType = "String"),
    })
    public Resp queryDevice(String  projectId,String powerRoomId) {
        List temperatureDeviceByTemperatureDeviceId = temperatureDeviceService.queryDevice(projectId,powerRoomId);
        return Resp.success(temperatureDeviceByTemperatureDeviceId);
    }
}
